<template>
  <div class="detailedCard">
    <a-card class="boxCard" :bordered="false">
      <div class="detailed">
        订单明细
      </div>
      <div class="boxCardContent">
        <div class="leftContent">
          <a-form layout="inline">
            <a-row :gutter="48">
              <a-col :lg="8" :md="12" :sm="12">
                <a-form-item label="服务合同号">
                  <a-input placeholder="请输入服务合同号" v-model="queryParam.serviceContractNo"/>
                </a-form-item>
              </a-col>
              <a-col :lg="8" :md="12" :sm="12">
                <a-form-item label="手机号">
                  <a-input placeholder="请输入手机号" v-model="queryParam.iphone"/>
                </a-form-item>
              </a-col>
              <a-col :lg="8" :md="12" :sm="12">
                <a-form-item label="身份证号">
                  <a-input placeholder="请输入身份证号" v-model="queryParam.idCard"/>
                </a-form-item>
              </a-col>
              <div v-if="advanced">
                <a-col :lg="8" :md="12" :sm="12">
                  <a-form-item label="车主姓名">
                    <a-input placeholder="请输入车主姓名" v-model="queryParam.carName"/>
                  </a-form-item>
                </a-col>
                <a-col :lg="8" :md="12" :sm="12">
                  <a-form-item label="车架号">
                    <a-input placeholder="请输入车架号" v-model="queryParam.vinNo"/>
                  </a-form-item>
                </a-col>
                <a-col :lg="8" :md="12" :sm="12">
                  <a-form-item label="车牌号">
                    <a-input placeholder="请输入车牌号" v-model="queryParam.carNumber"/>
                  </a-form-item>
                </a-col>
                <a-col :lg="12" :md="12" :sm="12">
                  <a-form-item label="车辆损失险保单号">
                    <a-input placeholder="请输入车辆损失险保单号" v-model="queryParam.lossPolicy"/>
                  </a-form-item>
                </a-col>
                <a-col :lg="12" :md="12" :sm="12">
                  <a-form-item label="车险承保公司">
                    <a-input placeholder="请输入车险承保公司" v-model="queryParam.insuranceCarriers"/>
                  </a-form-item>
                </a-col>
              </div>
              <a-col :lg="12" :md="12" :sm="12">
                <span class="table-page-search-submitButtons">
                  <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                  <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                  <img class="imgBtn" @click="isOpen()" src="../../assets/img/icon_arrow.png" alt="">
                </span>
              </a-col>
            </a-row>
          </a-form>
          <!-- <div class="table-operator">
          <a-button v-if="addEnable" type="primary" icon="plus" @click="$refs.modal.add()">新建</a-button>
          <a-dropdown v-if="removeEnable&&selectedRowKeys.length > 0">
            <a-button type="danger" icon="delete" @click="delByIds(selectedRowKeys)">删除</a-button>
          </a-dropdown>
        </div> -->
          <s-table
            size="default"
            ref="table"
            :scroll="{ x: 700 }"
            rowKey="id"
            :columns="columns"
            :data="loadData"
          >
            <span slot="action" slot-scope="test, record">
              <a v-if="true" @click="handleEditpreview(record)">预览</a>
              <a-divider type="vertical" />
              <a v-if="true" @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a v-if="true" @click="delByIds([record.id])">删除</a>
            </span>
          </s-table>
        </div>
      </div>
    </a-card>
    <div class="rightContent">
      <div class="newOrder">
        <img class="bg" src="./../../assets/img/btn_bk.png" alt="">
        <div @click="handleAdd()" class="newOrderconetnt">
          <img class="icon" src="./../../assets/img/btnicon_new.png" alt="">
          <span>新建订单</span>
        </div>
      </div>
      <div class="reportManagement">
        <img class="bg" src="./../../assets/img/btn_bk.png" alt="">
        <div class="reportManagementconetnt">
          <img class="icon" src="./../../assets/img/btnicon_man.png" alt="">
          <span>报表管理</span>
        </div>
      </div>
      <div class="outstandingOrders">
        <div class="detailed">
          未完成订单
        </div>
        <outstandOrderList :modal="outstandOrderList" />
      </div>
    </div>
    <sysBusinessInfo-modal ref="modal" @ok="handleOk"/>
    <preview-modal ref="preModal" @ok="handleOkpreview"/>
  </div>
</template>

<script>
import { STable } from '@/components'
import { getSysBusinessInfoList, delSysBusinessInfo } from '@/api/system'
import SysBusinessInfoModal from './modules/SysBusinessInfoModal.vue'
import { checkPermission } from '@/utils/permissions'
import outstandOrderList from './components/outstandOrderList'
import previewModal from './components/previewModal'
export default {
  name: 'Home',
  components: {
    STable,
    SysBusinessInfoModal,
    outstandOrderList,
    previewModal
  },
  data () {
    return {
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      form: this.$form.createForm(this),
      mdl: {},
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '订单号',
          width: 300,
          dataIndex: 'orderId'
        },
        {
          title: '下单日期',
          width: 200,
          dataIndex: 'orderTime',
          sorter: true
        },
        {
          title: '服务合同号',
          width: 200,
          dataIndex: 'serviceContractNo'
        },
        {
          title: '车辆组别',
          width: 100,
          dataIndex: 'carType'
        },
        {
          title: '业务员姓名',
          width: 150,
          dataIndex: 'saleName'
        },
        {
          title: '车辆品牌',
          width: 100,
          dataIndex: 'carBrand'
        },
        {
          title: '品牌型号',
          width: 100,
          dataIndex: 'brandModel'
        },
        {
          title: '车主姓名',
          width: 100,
          dataIndex: 'carName'
        },
        {
          title: '身份证号',
          width: 100,
          dataIndex: 'idCard'
        },
        {
          title: '服务权益人姓名',
          width: 100,
          dataIndex: 'serviceStakeholders'
        },
        {
          title: '手机号',
          width: 100,
          dataIndex: 'iphone'
        },
        {
          title: '车牌号',
          width: 100,
          dataIndex: 'carNumber'
        },
        {
          title: '车架号',
          width: 100,
          dataIndex: 'vinNo'
        },
        {
          title: '发动机号',
          width: 100,
          dataIndex: 'engineNo'
        },
        {
          title: '车险承保公司',
          width: 100,
          dataIndex: 'insuranceCarriers'
        },
        {
          title: '车辆损失险保单号',
          width: 100,
          dataIndex: 'lossPolicy'
        },
        {
          title: '保额',
          width: 100,
          dataIndex: 'insuredAmount'
        },
        {
          title: '商业险起保日期',
          width: 300,
          dataIndex: 'insuranceStartdate',
          sorter: true
        },
        {
          title: '投保方案',
          width: 100,
          dataIndex: 'insuranceScheme'
        },
        {
          title: '保险费',
          width: 100,
          dataIndex: 'insurancePremium'
        },
        {
          title: '赔偿限额',
          width: 100,
          dataIndex: 'compensationLimit'
        },
        {
          title: '操作',
          dataIndex: 'action',
          fixed: 'right',
          width: 150,
          scopedSlots: { customRender: 'action' }
        }
      ],
      range: null,
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return getSysBusinessInfoList(Object.assign(parameter, this.queryParam))
      },
      selectedRowKeys: [],
      selectedRows: [],
      addEnable: checkPermission('system:sysBusinessInfo:add'),
      editEnabel: checkPermission('system:sysBusinessInfo:edit'),
      removeEnable: checkPermission('system:sysBusinessInfo:remove')
    }
  },
  filters: {
  },
  created () {
  },
  methods: {
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleAdd () {
      this.$refs.modal.add()
    },
    handleEdit (record) {
      this.$refs.modal.edit(record)
    },
    handleEditpreview (record) {
      this.$refs.preModal.edit(record)
    },
    outstandOrderList (record) {
      this.$refs.modal.edit(record)
    },
    handleOk () {
      this.$refs.table.refresh(true)
      console.log('handleSaveOk')
    },
    handleOkpreview () {
      this.$refs.table.refresh(true)
    },
    delByIds (ids) {
      delSysBusinessInfo({ ids: ids.join(',') }).then(res => {
        if (res.code === 0) {
          this.$message.success('删除成功')
          this.handleOk()
        } else {
          this.$message.error(res.msg)
        }
        this.selectedRowKeys = []
      })
    },
    isOpen () {
      this.advanced = !this.advanced
    }
  },
  watch: {
    /*
      'selectedRows': function (selectedRows) {
        this.needTotalList = this.needTotalList.map(item => {
          return {
            ...item,
            total: selectedRows.reduce( (sum, val) => {
              return sum + val[item.dataIndex]
            }, 0)
          }
        })
      }
      */
  }
}
</script>

<style lang="less" scoped>
  .detailedCard{
    display: flex;
    width: 100%;
  }
  .boxCard{
    width: 74%;
    height: auto;
  }
  .boxCardContent{
    margin-top: 30px;
  }
  /deep/ .ant-card-body{
    padding: 0;
  }
  .leftContent{
    width: 100%;
    padding: 0 32px;
  }
  /deep/ .table-page-search-wrapper .ant-form-inline .ant-form-item .ant-form-item-control{
    max-width: 180px;
    min-width: 140px;
  }
  /deep/ .ant-col{
    padding-left: 0!important;
    padding-right: 0!important;
  }
  /deep/ .ant-form .ant-row{
    margin-left: 0!important;
    margin-right: 0!important;
  }
  .detailed {
    height: 55px;
    font-family: 'PingFangSC-Medium';
    font-size: 16px;
    color: rgba(0,0,0,0.85);
    font-weight: 500;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-left: 16px;
  }
  .rightContent{
    flex: 1;
    margin-left: 20px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    .newOrder{
      position: relative;
      cursor: pointer;
      height: 104px;
      border-radius: 4px;
      font-family: 'PingFangSC-Regular';
      font-size: 20px;
      color: #227FE6;
      font-weight: 400;
      display: flex;
      justify-content: center;
      align-items: center;
      .bg{
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 0;
      }
      .newOrderconetnt{
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        .icon{
          width: 54px;
          margin-right: 13px;
        }
      }
    }
    .reportManagement{
      position: relative;
      cursor: pointer;
      height: 104px;
      border-radius: 4px;
      margin: 20px 0;
      font-family: 'PingFangSC-Regular';
      font-size: 20px;
      color: #227FE6;
      font-weight: 400;
      display: flex;
      justify-content: center;
      align-items: center;
      .bg{
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 0;
      }
      .reportManagementconetnt{
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        .icon{
          width: 54px;
          margin-right: 13px;
        }
      }

    }
    .outstandingOrders{
      height: 100%;
      background: #fff;
      border-radius: 4px;
      display: flex;
      flex-direction: column;
    }
  }
  .imgBtn{
    width: 12px;
    margin-left: 23px;
    cursor: pointer;
  }
</style>
